package com.sun.file.quartz;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import com.sun.dao.TaaDqmAlarmMapper;
import com.sun.dao.TaaDqmDictMapper;
import com.sun.file.FileMatchThread;
import com.sun.model.TaaDqmAlarm;

public class FileJob implements Job {

	public void execute(JobExecutionContext jobContent) throws JobExecutionException {
		
		ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(4, 5, 4, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5),new ThreadPoolExecutor.CallerRunsPolicy());
		
		JobDataMap dataMap = jobContent.getJobDetail().getJobDataMap();
		
		String path=dataMap.getString("path");
		
		String fileNamePattern=dataMap.getString("fileNamePattern");
		
		String grepBeforeLineCount=dataMap.getString("logOutPutBeforeLineCountPattern");
		
		String grepAfterLineCount=dataMap.getString("logOutPutAfterLineCountPattern");
		
		String pattern=dataMap.getString("logParseParttern");
		
		String dealType=dataMap.getString("logDealType");
		
		
		
		String modulueID=dataMap.getString("modulueID");
		
		poolExecutor.execute(new FileMatchThread(path,fileNamePattern,
									Integer.parseInt(grepBeforeLineCount),
									Integer.parseInt(grepAfterLineCount),
									pattern,dealType,modulueID));
		
		poolExecutor.shutdown();
	}

}
